<?php

namespace Laoha\Blog;

use Encore\Admin\Admin;
use Encore\Admin\Extension;

class Blog extends Extension
{
    public $name = 'blog';
	
	public $migrations = __DIR__.'/../migrations/';

    public $views = __DIR__.'/../resources/views';

    public $assets = __DIR__.'/../resources/assets';


    public static function boot()
    {
        //static::registerRoutes();
        Admin::extend('laoha-blog', __CLASS__);
    }
/*
    protected static function registerRoutes()
    {
        parent::routes(function ($router) {
            $router->resource('apps/laoha_blog', 'Laoha\Blog\Admin\Controllers\LaohaBlogController')->names('admin.apps.laoha_blog');
			$router->post('apps/laoha_blog/restore', 'Laoha\Blog\Admin\Controllers\LaohaBlogController@restore')->name('admin.apps.laoha_blog.restore');
        });
    }
*/
    public static function import()
    {
		parent::createMenu('Blog Manager', 'apps/blog', 'fa-compass');
        parent::createPermission('Blog Manager','ext.blog', 'apps/blog/*');
		$info = require_once __DIR__ . '/info.php';
		$item = $info['item'];
		$apps = $info['apps'];
        \App\Models\Item::create([
            'name'   => $item['name'],
            'title'  => $item['title'],
            'desc'   => $item['desc'] ?? '',
            'author' => $item['author'] ?? '',
            'email' => $item['email'] ?? '',
			'homepage' => $item['homepage'] ?? '',
			'ver' => $item['ver'] ?? '',
			'is_dev' => empty($item['is_dev']) ? 0 : 1,
			'status' => 1
        ]);

		foreach($apps as $app){
			$data = [
				'name'   => $app['name'],
				'title'  => $app['title'],
				'item_name'=> $item['name'],
				'exts'   => $app['exts'] ?? Null,
 				'commons'  => $app['commons'] ?? Null,
				'set_form' => $app['set_form'] ?? Null,
				'cate_set_form' => $app['cate_set_form'] ?? Null,
				'def_sets' =>$app['def_sets'] ?? Null,
				'status' => 1
			];
			\App\Models\App::create($data);	
		}
    }

}